<template>
  <div class="mui-numbox" data-numbox-min="1">
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input class="mui-input-numbox" type="number" value="1" ref="number" @change="countChanged" />
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>
<script>
import mui from "../../lib/mui/js/mui.min.js";
export default {
  data() {
    return {};
  },
  methods: {
    countChanged() {
      this.$emit('getcount',parseInt(this.$refs.number.value))
    },
  },
  mounted() {
    //初始化数字选择框组件
    mui(".mui-numbox").numbox();
  },
  props: ["max"], //接受父组件传过来的库储量 max
  watch: {
    //因为从服务端拿存库是异步操作，所以需要监测数据，当数据改变调用一次，最终得到number类型的数据
    max: function (newVal, oldVal) {
      mui(".mui-numbox").numbox().setOption("max", newVal);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>